package com.supreme.studyserver.config;

import com.supreme.studyserver.service.noinject.OrderInfoService;
import com.supreme.studyserver.service.noinject.OrderSrcService;
import com.supreme.studyserver.service.noinject.UserInfoService;
import com.supreme.studyserver.service.noinject.UserSrcService;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "supreme.server.config")
@ConditionalOnProperty(value = "supreme.server.config.enable", havingValue = "true")
public class SupremeServerConfig {

    private Boolean enable;

    private String name;

    private Integer type;

    @Bean
    @ConditionalOnProperty(prefix = "supreme.server.config.user", name = "enable", havingValue = "true")
    public UserInfoService userInfoService() {
        return new UserInfoService();
    }

    @Bean
    @ConditionalOnProperty(prefix = "supreme.server.config.order", name = "enable", havingValue = "true")
    public OrderInfoService orderInfoService() {
        return new OrderInfoService();
    }

    @Bean
    @ConditionalOnResource(resources = "user-src.txt")
    public UserSrcService userSrcService() {
        return new UserSrcService();
    }

    @Bean
    @ConditionalOnResource(resources = "order-src.txt")
    public OrderSrcService orderSrcService() {
        return new OrderSrcService();
    }
}
